package Servlet.TeacherServlet;

import Entity.Course;
import Service.TeacherService.TeacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/*
负责教师 发布课程 数据接口
 */
@WebServlet(value = "/teacherReleaseCourse")
public class TeacherReleaseCourse extends HttpServlet {

    private TeacherService teacherService = new TeacherService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");


        String courseName = request.getParameter("courseName");
        String courseType = request.getParameter("courseType");
        float courseCredit = Float.parseFloat(request.getParameter("courseCredit"));
        int courseHour = Integer.parseInt(request.getParameter("courseHour"));
        int courseVolume = Integer.parseInt(request.getParameter("courseVolume"));
        String courseDesc = request.getParameter("courseDesc");
        String teacherId = request.getParameter("teacherId");

        Course course = new Course();

        course.setCourseName(courseName);
        course.setCourseType(courseType);
        course.setCourseCredit(courseCredit);
        course.setCourseHour(courseHour);
        course.setCourseVolume(courseVolume);
        course.setCourseDesc(courseDesc);
        course.setTeacherId(teacherId);


        int status = teacherService.insertCourseInfo(course);


        PrintWriter out = response.getWriter();
        out.print(status);
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
